//
//  HYVideoThemeView.m
//  _normal
//
//  Created by Ezra on 16/6/7.
//  Copyright © 2016年 Ezra. All rights reserved.
//

#import "HYVideoThemeView.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "HYThemeItem.h"

@interface HYVideoThemeView()

@property (weak, nonatomic) IBOutlet UIImageView *videoView;


@end

@implementation HYVideoThemeView

-(void)setItem:(HYThemeItem *)item
{
    [super setItem:item];

    
    self.videoView.layer.cornerRadius = 20 ;

    
    self.videoView.layer.masksToBounds = YES;
    
    NSString * urlStr = @"";
    if([self hasChinese:item.avatar]){
    urlStr  =  [item.avatar stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    }else{
        urlStr = item.avatar;
    }
    


    [self.videoView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"ic_temple_item01.png"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        
        NSLog(@"%@", error);
        
    }];
    
    
    
 
}

//判断是否有中文
-(BOOL)hasChinese:(NSString *)str {
    for(int i=0; i< [str length];i++){
        int a = [str characterAtIndex:i];
        if( a > 0x4e00 && a < 0x9fff)
        {
            
            return YES;
            
        }
        
    }
    return NO;}





@end
